package com.pansoft.kline.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.efounder.utils.JfResourceUtil;
import com.pansoft.kline.model.KIndexPopBean;
import com.pansoft.openplanet.R;

import java.util.List;

public class KIndexPopAdapter extends BaseAdapter {

    private Context context;
    private List<KIndexPopBean> list;

    public KIndexPopAdapter(Context context, List<KIndexPopBean> data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.chart_k_index_pop_grid_item,
                    null, false);
            viewHolder.textView = convertView.findViewById(R.id.tv_K_index);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.textView.setText(list.get(position).getName());
        if (list.get(position).isSelected()) {
            viewHolder.textView.setTextColor(JfResourceUtil.getSkinColor(R.color.chart_accent_text_color));
        } else {
            viewHolder.textView.setTextColor(JfResourceUtil.getSkinColor(R.color.main_text_color));
        }

        return convertView;
    }

    public class ViewHolder{
        TextView textView;
    }

}
